"""
你有个目录，里面是程序（假如是C或者是Python），统计一下你写过多少行代码。
包括空行和注释，但是要分别（例如C程序多少行，Python程序多少行，等等）列出来。
"""
import os


def code_lines(dir_path):
    py_lines = 0
    c_lines = 0
    for root, dirs, files in os.walk(dir_path):
        for file_name in files:
            file_path = os.path.join(root, file_name)
            if file_path[-3:] == ".py":
                with open(file_path, 'r', encoding="utf-8") as fp:
                    for line in fp:
                        py_lines += 1
            if file_path[-2:] == ".c":
                with open(file_path, 'r', encoding="utf-8") as fp:
                    for line in fp:
                        c_lines += 1
    return py_lines, c_lines


path = input('请输入文件目录:\n')
count_lines = code_lines(path)
print(f'Python程序是{count_lines[0]}行，C程序是{count_lines[1]}行')


